import { Canvas } from "butterfly-dag";
import $ from "jquery";

export default class BluePrintCanvas extends Canvas {
  [key: string]: any;
  constructor(props) {
    super(props);
    this.initCanvasEvent();
  }
  initCanvasEvent = () => {
    this.on("system.node.click", ({ node }) => {
      this.__clearAllNodeActive();
      this.__clearAllEdgeActive();
      $(node.dom).addClass("visbar-active-node");
      this.activeNode = node;
    });
    this.on("system.link.click", ({ edge }) => {
      this.__clearAllNodeActive();
      this.__clearAllEdgeActive();
      $(edge.dom).addClass("visbar-active-edge");
      this.activeNode = edge;
    })
  }
  /** 清除所有node的激活状态 */
  __clearAllNodeActive = () => {
    (this.nodes || []).forEach(item => $(item.dom).removeClass("visbar-active-node"));
  }
  /** 清除所有edge的激活状态 */
  __clearAllEdgeActive = () => {
    (this.edges || []).forEach(item => $(item.dom).removeClass("visbar-active-edge"));
  }
}